Add an option to opt out of human-readable names - #27160
Conversation
Summary -- This PR closes #26320 by adding the new `lint.prefer-rule-codes-in-output` option that defaults to `false` and disables the use of human-readable rule names in most output formats, even in preview. This does not affect formats like JSON that include the name and code as separate fields. Test Plan -- New CLI test enabling the option
Memory usage reportMemory usage unchanged ✅ |
|
|
There was a problem hiding this comment.
Thank you. I'm a bit torn whether the option should be in lint or not. While it only applies to lints, it does change the CLI output, making it nice if it were next to output-format.
I also considered naming it output-prefer-rule-codes or output-prefer-codes, so that it sorts next to output-format.
No strong opinion on this, happy to go with what you choose.
| } | ||
| } | ||
| let code = if self.config.preview { | ||
| let code = if self.config.preview && !self.config.prefer_rule_codes { |
There was a problem hiding this comment.
We may use preview for more checks. But if not, could we set prefer_rule_codes to !linter.preview.is_enabled() || self.config.prefer_rule_codes? It may allow you to reduce the arguments that you need to pass to the rendering code
There was a problem hiding this comment.
Hmm, that's interesting. Codex originally tried to fold the preview && !prefer_rule_codes check into the existing preview field, which does work since this is all we're currently using preview for. I kept them separate in case we needed preview again in the future and because it seemed confusing to include that check in a field named preview. Removing the preview field and folding the condition into prefer_rule_codes sounds more appealing.
There was a problem hiding this comment.
After thinking about this a bit more, I'm again leaning toward keeping the fields separate. In a very strict sense, we are still using preview for two features: showing the real severity in JSON output and human-readable names. It seems possible that we will expand the preview-gate for severity in the near future and may want to keep that separate from human-readable names.
Happy to follow up if you feel strongly, of course.
Conceptually I think I like |
Summary
This PR closes #26320 by adding the new
output-prefer-rule-codesoption that defaults tofalseand disables the use of human-readable rule names in most output formats, even in preview.This does not affect formats like JSON that include the name and code as separate fields.
Test Plan
New CLI test enabling the option, as well as manual testing in the playground:
and in VS Code:
Note the human-readable name in the
ruff: ignorecomment, which shows that preview is enabled, while the(F401)in the output shows that the setting is being used.